#!/usr/bin python
# -*- coding: utf-8 -*-
# @Time    : 2023/3/10 11:32
# @Author  : hhr


import undetected_chromedriver as uc
import ssl, time

from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By

ssl._create_default_https_context = ssl._create_unverified_context

uc.TARGET_VERSION = 91

# chrome_options = uc.ChromeOptions()       # 实例化options
# chrome_options.add_argument("--disable-extensions")
# chrome_options.add_argument("--disable-popup-blocking")
# chrome_options.add_argument("--profile-directory=Default")
# chrome_options.add_argument("--ignore-certificate-errors")
# chrome_options.add_argument("--disable-plugins-discovery")
# chrome_options.add_argument("--incognito")
# chrome_options.add_argument('--no-first-run')
# chrome_options.add_argument('--no-service-autorun')
# chrome_options.add_argument('--no-default-browser-check')
# chrome_options.add_argument('--password-store=basic')
# chrome_options.add_argument('--no-sandbox')

driver = uc.Chrome()
driver.get('https://cpquery.cponline.cnipa.gov.cn/chinesepatent/index')

time.sleep(5)
driver.find_element_by_xpath('//div[@class="el-radio-group title-group"]/label[3]').click()
driver.find_element_by_xpath('//input[@type="text"]').clear()
driver.find_element_by_xpath('//input[@type="text"]').send_keys('42264')
time.sleep(2)
driver.find_element_by_xpath('//input[@type="password"]').clear()
driver.find_element_by_xpath('//input[@type="password"]').send_keys('Xhhg2019@')
time.sleep(20)
input("目标页面：")
# driver.find_element_by_xpath('//*[@id="__next"]/div[1]/div[2]/div/div[1]/div[2]/header/nav/a[2]').click()
for sqh in ['2022114018683', '2020114280249', '2020113029874']:
    print("ok!")
    # driver.find_elements(By.CLASS_NAME, "el-tree-node is-focusable")[3].click()
    url = f"https://cpquery.cponline.cnipa.gov.cn/detail/index?zhuanlisqh={sqh}&anjianbh"
    handles = driver.window_handles
    driver.switch_to.window(handles[-1])
    driver.get_screenshot_as_file("save.png")
    print("\n")
time.sleep(1000)
driver.close()

# https://cpquery.cponline.cnipa.gov.cn/chinesepatent/index

